﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace NCKH.Personal
{
    public partial class hopdongungdung : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ConfigCKEditor();
            if (!IsPostBack)
            {
                hientendetai();
                hienCQCQ();
            }
        }
        protected void hientendetai()
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand("select_tendetai1", cnn))
                {
                    cnn.Open();
                    cmd.CommandType = CommandType.Text;
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        drlnhomud.Items.Insert(0, "--chọn tên Đề Tài---");
                        if (rd.HasRows)
                        {
                            while (rd.Read())
                            {
                                drlnhomud.Items.Add(new ListItem(rd["TenDT"].ToString(), rd["ManhomUD"].ToString()));
                            }
                        }
                        else

                            btok.Enabled = false;
                        rd.Close();
                    }
                    cnn.Close();
                }
            }
        }

        protected void btthem_Click(object sender, EventArgs e)
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand("insert_hopdongTKUD", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@ManhomUD", drlnhomud.SelectedValue);
                    cmd.Parameters.AddWithValue("@MaCQCQ", drlcqcq.SelectedValue);
                    cmd.Parameters.AddWithValue("@TongkinhphiDK", txtkinhphi.Text);
                    cmd.Parameters.AddWithValue("@Dieukhoan", ckdieukhoan.Text);
                    cmd.Parameters.AddWithValue("@Ngaycohieuluc", txtngayhieuluc.Text);
                    cmd.Parameters.AddWithValue("@Ngaylaphopdong", txtngaylap.Text);
                    cnn.Open();
                    cmd.ExecuteNonQuery();
                    cnn.Close();
                    txtbena.Text = txtbenb.Text = txtngayhieuluc.Text = txtngaylap.Text = string.Empty;

                }
            }
        }
        protected void hienCQCQ()
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            string select_CQCQ = "SELECT MaCQCQ, TenCQCQ FROM COQUANCHUQUAN";
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand(select_CQCQ, cnn))
                {
                    cmd.CommandType = CommandType.Text;
                    cnn.Open();
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        drlcqcq.Items.Insert(0, "--Chọn CQCQ---");
                        if (rd.HasRows)
                        {
                            while (rd.Read())
                            {
                                drlcqcq.Items.Add(new ListItem(rd["TenCQCQ"].ToString(), rd["MaCQCQ"].ToString()));
                            }
                        }
                        else
                            btok.Enabled = false;
                        rd.Close();
                    }
                    cnn.Close();
                }
            }
        }
        protected void ConfigCKEditor()
        {
            ckdieukhoan.config.toolbar = new object[] { new object[] { "Bold", "Italic","Underline", "-","Subscript", "Superscript", "NumberedList", "BulletedList", "-", "Link", "Unlink", "-", "About" }, 
                new object[] { "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "-", "Print", "SpellChecker", "Scayt" }, };
        }
        protected void btin_Click(object sender, EventArgs e)
        {

        }

        protected void cldngaynopTM_SelectionChanged1(object sender, EventArgs e)
        {
            txtngaylap.Text = cldngaynopTM.SelectedDate.ToShortDateString();
        }

        protected void cldngaycohieuluc_SelectionChanged(object sender, EventArgs e)
        {
            txtngayhieuluc.Text = cldngaycohieuluc.SelectedDate.ToShortDateString();
        }

        protected void bthuy_Click(object sender, EventArgs e)
        {
            txtbena.Text = txtbenb.Text = txtngayhieuluc.Text = txtngaylap.Text = string.Empty;
        }
    }
}